
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>db模块 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="http.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    快速开始
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../start/param.html">
            
                <a href="../start/param.html">
            
                    
                    参数获取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../start/crud.html">
            
                <a href="../start/crud.html">
            
                    
                    增删改查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../start/table.html">
            
                <a href="../start/table.html">
            
                    
                    单表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../start/page.html">
            
                <a href="../start/page.html">
            
                    
                    分页查询
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    核心模块
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="db.html">
            
                <a href="db.html">
            
                    
                    db模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="http.html">
            
                <a href="http.html">
            
                    
                    http模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="log.html">
            
                <a href="log.html">
            
                    
                    log模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="env.html">
            
                <a href="env.html">
            
                    
                    env模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    特殊函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../function/agg.html">
            
                <a href="../function/agg.html">
            
                    
                    聚合函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../function/date.html">
            
                <a href="../function/date.html">
            
                    
                    日期函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../function/string.html">
            
                <a href="../function/string.html">
            
                    
                    字符串函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../function/array.html">
            
                <a href="../function/array.html">
            
                    
                    数组函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../function/math.html">
            
                <a href="../function/math.html">
            
                    
                    数学函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../function/other.html">
            
                <a href="../function/other.html">
            
                    
                    其他函数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    对象方法
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../object/object.html">
            
                <a href="../object/object.html">
            
                    
                    Object对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../object/number.html">
            
                <a href="../object/number.html">
            
                    
                    Number对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../object/list.html">
            
                <a href="../object/list.html">
            
                    
                    数组&集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../object/date.html">
            
                <a href="../object/date.html">
            
                    
                    Date对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../object/class.html">
            
                <a href="../object/class.html">
            
                    
                    Class对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../object/pattern.html">
            
                <a href="../object/pattern.html">
            
                    
                    Patter对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    脚本语法
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../syntax/keyword.html">
            
                <a href="../syntax/keyword.html">
            
                    
                    关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../syntax/type.html">
            
                <a href="../syntax/type.html">
            
                    
                    类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../syntax/yunsuan.html">
            
                <a href="../syntax/yunsuan.html">
            
                    
                    运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../syntax/yiyuan.html">
            
                <a href="../syntax/yiyuan.html">
            
                    
                    运算符示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../syntax/for.html">
            
                <a href="../syntax/for.html">
            
                    
                    for循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../syntax/import.html">
            
                <a href="../syntax/import.html">
            
                    
                    导入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../syntax/async.html">
            
                <a href="../syntax/async.html">
            
                    
                    异步
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >db模块</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h4 id="&#x5F15;&#x7528;&#x6A21;&#x5757;">&#x5F15;&#x7528;&#x6A21;&#x5757;</h4>
<p>db&#x662F;&#x9ED8;&#x8BA4;&#x5F15;&#x5165;&#x7684;&#x6A21;&#x5757;&#xFF0C;&#x6240;&#x4EE5;&#x65E0;&#x9700;&#x5F15;&#x5165;</p>
<h4 id="select">select</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>:<code>String</code></li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>List&lt;Map&lt;String,Object&gt;&gt;</code></li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x67E5;&#x8BE2;<code>List</code>&#x7ED3;&#x679C;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> db.select(<span class="hljs-string">&apos;select * from sys_user&apos;</span>);
</code></pre>
<h4 id="selectint">selectInt</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>:<code>String</code></li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>Integer</code></li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x67E5;&#x8BE2;<code>int</code>&#x7ED3;&#x679C;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// &#x9700;&#x8981;&#x4FDD;&#x8BC1;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x4E00;&#x884C;&#x4E00;&#x5217;</span>
<span class="hljs-keyword">return</span> db.selectInt(<span class="hljs-string">&apos;select count(*) from sys_user&apos;</span>);
</code></pre>
<h4 id="selectone">selectOne</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>:<code>String</code></li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>Map&lt;String,Object&gt;</code></li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x67E5;&#x8BE2;&#x5355;&#x4E2A;&#x5BF9;&#x8C61;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> db.selectOne(<span class="hljs-string">&apos;select * from sys_user limit 1&apos;</span>);
</code></pre>
<h4 id="selectvalue">selectValue</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>:<code>String</code></li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>Object</code></li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x67E5;&#x8BE2;&#x5355;&#x4E2A;&#x503C;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">//&#x9700;&#x8981;&#x4FDD;&#x8BC1;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x4E00;&#x884C;&#x4E00;&#x5217; </span>
<span class="hljs-keyword">return</span> db.selectValue(<span class="hljs-string">&apos;select user_name from sys_user limit 1&apos;</span>);
</code></pre>
<h4 id="page">page</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>:<code>String</code></li>
<li>&#x5165;&#x53C2;&#xFF1A;<code>limit</code> : <code>long</code> &#x53EF;&#x7701;&#x7565;</li>
<li>&#x5165;&#x53C2;&#xFF1A;<code>offset</code> : <code>long</code> &#x53EF;&#x7701;&#x7565;</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>Object</code> &#x9ED8;&#x8BA4;&#x8FD4;&#x56DE;&#x4E3A;Object&#xFF0C;&#x5982;&#x679C;&#x81EA;&#x5B9A;&#x4E49;&#x4E86;&#x5206;&#x9875;&#x7ED3;&#x679C;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x81EA;&#x5B9A;&#x4E49;&#x7ED3;&#x679C;</li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x5206;&#x9875;&#x67E5;&#x8BE2;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> db.page(<span class="hljs-string">&apos;select * from sys_user&apos;</span>);
</code></pre>
<h4 id="update">update</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>:<code>String</code></li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>Integer</code></li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x6267;&#x884C;&#x589E;&#x5220;&#x6539;&#x64CD;&#x4F5C;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> db.update(<span class="hljs-string">&apos;delete from sys_user&apos;</span>);
</code></pre>
<h4 id="insert">insert</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>&#xFF1A;<code>String</code></li>
<li>&#x5165;&#x53C2;&#xFF1A; <code>id</code>&#xFF1A; <code>String</code>&#xFF0C;&#x4E3B;&#x952E;&#x5217;&#xFF0C;&#x53EF;&#x7A7A;&#xFF0C;&#x5982;&#x65E0;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#x4E0D;&#x9700;&#x8981;&#x4F20;&#x5165;</li>
<li>&#x8FD4;&#x56DE;&#x503C;: <code>Object</code></li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> db.insert(<span class="hljs-string">&quot;insert into sys_user(username,password) values(&apos;admin&apos;,&apos;admin)&quot;</span>);
</code></pre>
<h4 id="batchupdate">batchUpdate</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>sql</code>&#xFF1A;<code>String</code></li>
<li>&#x5165;&#x53C2;&#xFF1A; <code>batchArgs</code>&#xFF1A; <code>List&lt;Object[]&gt;</code>&#x6570;&#x636E;&#xFF0C;&#x5360;&#x4F4D;&#x7B26;&#x548C;&#x6570;&#x7EC4;&#x4E0B;&#x6807;&#x5BF9;&#x5E94;</li>
<li>&#x8FD4;&#x56DE;&#x503C;: <code>int</code></li>
</ul>
<pre><code class="lang-js">return db.batchUpdate(&quot;&quot;&quot;
    update sys_dict set is_del = ? where is_del = ?
&quot;&quot;&quot;, [
    [&quot;1&quot;, &quot;0&quot;].toArray()
])
</code></pre>
<h4 id="cache">cache</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>cacheName</code>:<code>String</code></li>
<li>&#x5165;&#x53C2;&#xFF1A;<code>ttl</code>:<code>long</code> &#x7F13;&#x5B58;&#x6709;&#x6548;&#x671F;&#xFF0C;&#x5355;&#x4F4D;&#x6BEB;&#x79D2;&#xFF0C;&#x53EF;&#x7701;&#x7565;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x914D;&#x7F6E;&#x7684;&#x503C;</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>db</code> //&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x5B9E;&#x4F8B;&#xFF0C;&#x5373;&#x53EF;&#x4EE5;&#x94FE;&#x5F0F;&#x8C03;&#x7528;</li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x4F7F;&#x7528;&#x7F13;&#x5B58;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// &#x4F7F;&#x7528;&#x7F13;&#x5B58;&#x540D;&#x4E3A;user&#x7684;&#x67E5;&#x8BE2;</span>
<span class="hljs-keyword">return</span> db.cache(<span class="hljs-string">&apos;user&apos;</span>).select(<span class="hljs-string">&apos;select * from sys_user&apos;</span>);
</code></pre>
<h4 id="deletecache">deleteCache</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>cacheName</code>:<code>String</code></li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>db</code> //&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x5B9E;&#x4F8B;&#xFF0C;&#x5373;&#x53EF;&#x4EE5;&#x94FE;&#x5F0F;&#x8C03;&#x7528;</li>
<li>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x5220;&#x9664;&#x540D;&#x4E3A;<code>cacheName</code>&#x7684;&#x7F13;&#x5B58;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5220;&#x9664;&#x540D;&#x4E3A;user&#x7684;&#x7F13;&#x5B58;</span>
db.deleteCache(<span class="hljs-string">&apos;user&apos;</span>);
</code></pre>
<h4 id="transaction">transaction</h4>
<ul>
<li><p>&#x5165;&#x53C2;&#xFF1A;<code>callback</code>:<code>Function</code>&#xFF0C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x7701;&#x7565;</p>
</li>
<li><p>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;<code>Object</code></p>
</li>
<li><p>&#x51FD;&#x6570;&#x8BF4;&#x660E;&#xFF1A;&#x5F00;&#x542F;&#x4E8B;&#x52A1;</p>
</li>
<li><p>&#x81EA;&#x52A8;&#x4E8B;&#x52A1;</p>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> val = db.transaction(()=&gt;{
    <span class="hljs-keyword">var</span> v1 = db.update(<span class="hljs-string">&apos;...&apos;</span>);
    <span class="hljs-keyword">var</span> v2 = db.update(<span class="hljs-string">&apos;....&apos;</span>);
    <span class="hljs-keyword">return</span> v2;
});
<span class="hljs-keyword">return</span> val;
</code></pre>
<ul>
<li>&#x624B;&#x52A8;&#x5F00;&#x542F;&#x4E8B;&#x52A1;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> tx = db.transaction();  <span class="hljs-comment">//&#x5F00;&#x542F;&#x4E8B;&#x52A1;</span>
<span class="hljs-keyword">try</span>{
    <span class="hljs-keyword">var</span> value = db.update(<span class="hljs-string">&apos;...&apos;</span>);
    tx.commit();    <span class="hljs-comment">// &#x63D0;&#x4EA4;&#x4E8B;&#x52A1;</span>
    <span class="hljs-keyword">return</span> value;
}<span class="hljs-keyword">catch</span>(e){
    tx.rollback();  <span class="hljs-comment">// &#x56DE;&#x6EDA;&#x4E8B;&#x52A1;</span>
}
</code></pre>
<h4 id="&#x5217;&#x540D;&#x8F6C;&#x6362;">&#x5217;&#x540D;&#x8F6C;&#x6362;</h4>
<ul>
<li>normal &#x5217;&#x540D;&#x4FDD;&#x6301;&#x539F;&#x6837;</li>
<li>camel &#x5217;&#x540D;&#x4F7F;&#x7528;&#x9A7C;&#x5CF0;&#x547D;&#x540D;</li>
<li>pascal &#x5217;&#x540D;&#x4F7F;&#x7528;&#x5E15;&#x65AF;&#x5361;&#x547D;&#x540D;</li>
<li>upper &#x5217;&#x540D;&#x4FDD;&#x6301;&#x5168;&#x5927;&#x5199;</li>
<li>lower &#x5217;&#x540D;&#x4FDD;&#x6301;&#x5168;&#x5C0F;&#x5199;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> db.camel().select(<span class="hljs-string">&apos;select * from sys_user&apos;</span>);
</code></pre>
<h4 id="&#x5355;&#x8868;&#x64CD;&#x4F5C;api">&#x5355;&#x8868;&#x64CD;&#x4F5C;API</h4>
<p>&#x64CD;&#x4F5C;&#x5165;&#x53E3;&#xFF1A;<code>db.table(&apos;table_name&apos;)</code></p>
<h4 id="logic">logic</h4>
<ul>
<li>&#x4F5C;&#x7528;:&#x8BBE;&#x7F6E;&#x672C;&#x67E5;&#x8BE2;&#x662F;&#x5E26;&#x6709;&#x903B;&#x8F91;&#x5220;&#x9664;&#x7684;,&#x5728;&#x6267;&#x884C;<code>delete</code>&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x4F1A;&#x8F6C;&#x6362;&#x4E3A;<code>update</code>&#x8BED;&#x53E5;&#xFF0C;&#x5728;&#x6267;&#x884C;<code>select</code>&#x76F8;&#x5173;&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x4F1A;&#x62FC;&#x63A5;<code>logic_field &lt;&gt; logic_value</code></li>
</ul>
<h4 id="withblank">withBlank</h4>
<ul>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x540E;&#x7EED;&#x63D2;&#x5165;&#x6216;&#x4FEE;&#x6539;&#x65F6;&#xFF0C;&#x4E0D;&#x8FC7;&#x6EE4;&#x7A7A;&#x503C;&#x3002;</li>
</ul>
<h4 id="column">column</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>column</code>: <code>String</code> &#x5217;&#x540D;</li>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x8981;&#x67E5;&#x8BE2;&#x5217;&#x7684;,<code>select</code>&#x8BED;&#x53E5;&#x4E2D;&#x6709;&#x6548;</li>
</ul>
<h4 id="column">column</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>column</code>: <code>String</code> &#x5217;&#x540D;</li>
<li>&#x5165;&#x53C2;&#xFF1A; <code>value</code> : <code>Object</code> &#x503C;</li>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x8981;&#x64CD;&#x4F5C;&#x7684;&#x5217;&#x7684;&#x503C;,&#x975E;<code>select</code>&#x8BED;&#x53E5;&#x4E2D;&#x6709;&#x6548;</li>
</ul>
<h4 id="primary">primary</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>primary</code>: <code>String</code> &#x4E3B;&#x952E;</li>
<li>&#x5165;&#x53C2;&#xFF1A;<code>defaultValue</code>: <code>Object</code> &#x63D2;&#x5165;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;</li>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x4E3B;&#x952E;&#x5217;&#xFF0C;&#x5728;<code>update</code>&#x4E2D;&#x8BED;&#x53E5;&#x6709;&#x6548;&#xFF0C;&#x6216;<code>save</code>&#x65B9;&#x6CD5;&#x5224;&#x65AD;&#x6807;&#x51C6;</li>
</ul>
<h4 id="insert">insert</h4>
<ul>
<li>&#x5165;&#x53C2;: <code>data</code> : <code>Map</code> <code>insert</code>&#x7684;&#x5217;&#x548C;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x901A;&#x8FC7;<code>column</code>&#x8BBE;&#x7F6E;)</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// insert into sys_user(user_name,role) values(&apos;&#x674E;&#x5BCC;&#x8D35;&apos;,&apos;admin&apos;)</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).insert({ user_name : <span class="hljs-string">&apos;&#x674E;&#x5BCC;&#x8D35;&apos;</span>, role : <span class="hljs-string">&apos;admin&apos;</span>})
</code></pre>
<h4 id="batchinsert">batchInsert</h4>
<ul>
<li>&#x5165;&#x53C2;: <code>collection</code> : <code>Collection</code> <code>insert</code>&#x7684;&#x5217;&#x548C;&#x503C;&#x7684;&#x96C6;&#x5408;</li>
<li>&#x5165;&#x53C2;: <code>batchSize</code> &#xFF1A; <code>int</code> batchSize</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// insert into sys_user(user_name,role) values(&apos;&#x674E;&#x5BCC;&#x8D35;&apos;,&apos;admin&apos;)</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).batchInsert([
    { user_name : <span class="hljs-string">&apos;&#x674E;&#x5BCC;&#x8D35;&apos;</span>, role : <span class="hljs-string">&apos;admin&apos;</span>},
    { user_name : <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>, role : <span class="hljs-string">&apos;admin&apos;</span>},
    { user_name : <span class="hljs-string">&apos;&#x7BA1;&#x7406;&#x5458;&apos;</span>, role : <span class="hljs-string">&apos;super-admin&apos;</span>},
])
</code></pre>
<h4 id="update">update</h4>
<ul>
<li>&#x5165;&#x53C2;: <code>data</code> : <code>Map</code> <code>insert</code>&#x7684;&#x5217;&#x548C;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x901A;&#x8FC7;<code>column</code>&#x8BBE;&#x7F6E;)</li>
<li>&#x5165;&#x53C2;&#xFF1A;<code>isUpdateBlank</code>: <code>boolean</code> &#x662F;&#x5426;&#x66F4;&#x65B0;&#x7A7A;&#x503C;&#x5B57;&#x6BB5;&#xFF08;&#x53EF;&#x7701;&#x7565;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;<code>false</code>&#xFF09;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// update sys_user set user_name = &apos;&#x738B;&#x4E8C;&#x72D7;&apos; where id = 1</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>).update({ id: <span class="hljs-number">1</span>, user_name : <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>})
</code></pre>
<h4 id="save">save</h4>
<ul>
<li>&#x5165;&#x53C2;: <code>data</code> : <code>Map</code> <code>insert</code>&#x6216;<code>update</code>&#x7684;&#x5217;&#x548C;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x901A;&#x8FC7;<code>column</code>&#x8BBE;&#x7F6E;)</li>
<li>&#x5165;&#x53C2;&#xFF1A; <code>beforeQuery</code> &#xFF1A; <code>boolean</code> &#x662F;&#x5426;&#x6839;&#x636E;id&#x67E5;&#x8BE2;&#x6709;&#x6CA1;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x9ED8;&#x8BA4;<code>false</code>)</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// insert into sys_user(id,user_name) values(&apos;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&apos;,&apos;&#x738B;&#x4E8C;&#x72D7;&apos;);</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>, uuid()).save({user_name: <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>});
<span class="hljs-comment">// insert into sys_user(user_name) values(&apos;&#x738B;&#x4E8C;&#x72D7;&apos;);</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>).save({user_name: <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>});
<span class="hljs-comment">// update sys_user set user_name = &apos;&#x738B;&#x4E8C;&#x72D7;&apos; where id = 1</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>).save({id: <span class="hljs-number">1</span>,user_name: <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>});
</code></pre>
<h4 id="select">select</h4>
<p>&#x67E5;&#x8BE2;list&#xFF08;&#x4E0E;db.select &#x4F5C;&#x7528;&#x76F8;&#x540C;&#xFF09;</p>
<pre><code class="lang-js"><span class="hljs-comment">// select * from sys_user</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).select()
</code></pre>
<h4 id="page">page</h4>
<p>&#x5206;&#x9875;&#x67E5;&#x8BE2;&#xFF08;&#x4E0E;db.page &#x4F5C;&#x7528;&#x76F8;&#x540C;&#xFF09;</p>
<pre><code class="lang-js"><span class="hljs-comment">// select * from sys_user</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).page()
</code></pre>
<h4 id="where">where</h4>
<p>&#x8BBE;&#x7F6E;&#x67E5;&#x8BE2;&#x6761;&#x4EF6;</p>
<ul>
<li>eq --&gt; <code>==</code></li>
<li>ne --&gt; <code>&lt;&gt;</code></li>
<li>lt --&gt; <code>&lt;</code></li>
<li>gt --&gt; <code>&gt;</code></li>
<li>lte --&gt; <code>&lt;=</code></li>
<li>gte --&gt; <code>&gt;=</code></li>
<li>in --&gt; <code>in</code></li>
<li>notIn --&gt; <code>not in</code></li>
<li>like --&gt; <code>like</code></li>
<li>notLike --&gt; <code>not like</code></li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// select * from sys_user where user_name like &apos;%&#x674E;&#x5BCC;&#x8D35;%&apos; and role = &apos;admin&apos;</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>)
    .where()
    .like(<span class="hljs-string">&apos;user_name&apos;</span>,<span class="hljs-string">&apos;%&#x674E;&#x5BCC;&#x8D35;%&apos;</span>)
    .eq(<span class="hljs-string">&apos;role&apos;</span>,<span class="hljs-string">&apos;admin&apos;</span>)
    .select()
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="http.html" class="navigation navigation-next navigation-unique" aria-label="Next page: http模块">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"db模块","level":"1.3.1","depth":2,"next":{"title":"http模块","level":"1.3.2","depth":2,"path":"module/http.md","ref":"module/http.md","articles":[]},"previous":{"title":"核心模块","level":"1.3","depth":1,"ref":"","articles":[{"title":"db模块","level":"1.3.1","depth":2,"path":"module/db.md","ref":"module/db.md","articles":[]},{"title":"http模块","level":"1.3.2","depth":2,"path":"module/http.md","ref":"module/http.md","articles":[]},{"title":"log模块","level":"1.3.3","depth":2,"path":"module/log.md","ref":"module/log.md","articles":[]},{"title":"env模块","level":"1.3.4","depth":2,"path":"module/env.md","ref":"module/env.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"module/db.md","mtime":"2023-12-28T04:17:24.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-01-02T08:17:25.965Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

